package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.util.*;
import cc.rengu.igas.momp.facade.bean.*;
import cc.rengu.igas.momp.facade.request.MchntMcManageRequest;
import cc.rengu.igas.momp.facade.response.MchntMcManageResponse;
import cc.rengu.jrbdp.register.realtime.client.RealTimeRegisterClient;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.base.StringUtil;
import cc.rengu.utility.dbs.Database;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 商户营销活动管理
 *
 * @author liujinan
 * @version 1.0.0
 * @date 2020/6/11
 */
public class MchntMcManageService extends RadpService {

    private String globalTimeStamp;
    private String globalOprId;
    private String globalMcNo;
    private String globalMcType;
    private String globalInstId;
    private String globalTraceNo;
    private String globalTxnDate;
    private String globalQueryOrgId;
    //商户所属机构及上属机构链表
    private List<McOrgInfoBean> globalOrgInfoList;
    private BigDecimal zero = BigDecimal.ZERO;
    /**
     * 批量任务注册参数类型 PARAM_TYPE
     */
    private static final String MOMP_RBDP_ADDRESS = "MOMP_RBDP_ADDRESS";
    /**
     * 批量任务注册地址参数键值 PARAM_KEY
     */
    private static final String MOMP_RBDP_REGISTER_ADDRESS = "MOMP_RBDP_REGISTER_ADDRESS";

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {
            MchntMcManageRequest mchntMcManageRequest = new MchntMcManageRequest();
            ConvertUtil.convertOutput(mchntMcManageRequest);

            /* 检查请求报文并赋值全局变量 */
            messageValidation(mchntMcManageRequest);

            MchntMcManageResponse mchntMcManageResponse = new MchntMcManageResponse();
            mchntMcManageResponse.setHeader(mchntMcManageRequest.getHeader());
            BizResponse<MchntMcManageResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(mchntMcManageResponse);

            //调用流程处理
            BizResponse<MchntMcManageResponse> bizResponseNew = manageMoneyOffOrCouponMc(mchntMcManageRequest, mchntMcManageResponse, xmlTreeUtil);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e));
            }
        }
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 对客类活动管理
     *
     * @param mchntMcManageRequest  对客类营销活动管理接口请求对象
     * @param mchntMcManageResponse 对客类营销活动管理接口应答对象
     * @param xmlTreeUtil           内部XML树
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.MchntMcManageResponse> 减免类营销活动管理接口应答对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11
     */
    private BizResponse<MchntMcManageResponse> manageMoneyOffOrCouponMc(MchntMcManageRequest mchntMcManageRequest, MchntMcManageResponse mchntMcManageResponse, XmlTreeUtil xmlTreeUtil) throws Exception {
        BizResponse<MchntMcManageResponse> bizResponse = new BizResponse<>();

        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();

        //如果是免充值的活动，需要判断是否是特殊费率商户
        String budgetRechargeMethod = mchntMcManageRequest.getMcInfoObj().getBudgetRechargeMethod();
        if (CommonConstant.ZERO_COMMON_CONSTANT.equals(budgetRechargeMethod)) {
            rglog.info("将要创建的活动预算充值方式为活动后结算，开始判断是否是特殊费率商户...");
            //判断上送商户是否有特殊费率商户
            if (null != mchntMcManageRequest.getMchntInfoList() && !mchntMcManageRequest.getMchntInfoList().isEmpty()) {
                for (McMchntInfoBean mcMchntInfoBean : mchntMcManageRequest.getMchntInfoList()) {
                    //查出该商户下所有的费率模板
                    List<TBMchntFeeInfo> tbMchntFeeInfoList = mchntInfoMapper.selectMchntFeeInfoListByMchntNo(globalInstId, mcMchntInfoBean.getMchntNo());
                    if (null != tbMchntFeeInfoList && tbMchntFeeInfoList.size() > 0) {
                        //取费率模板为0的数据
                        tbMchntFeeInfoList = tbMchntFeeInfoList.stream().filter(item -> item.getFeeInputMode().equals(CommonConstant.ZERO_COMMON_CONSTANT)).collect(Collectors.toList());
                        if (tbMchntFeeInfoList.size() > 0) {
                            rglog.error("交易流水号：<{}>, 商户<{}>费率信息表存在特殊费率！", mchntMcManageRequest.getHeader().getTraceNo(), mcMchntInfoBean.getMchntNo());
                            throw new BizException(RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespCode(), RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespDesc());
                        }
                    }
                }
            }
        }

        //判断查询类型
        String queryType = mchntMcManageRequest.getQueryType();
        String queryRole = mchntMcManageRequest.getQueryRole();
        String oprType = mchntMcManageRequest.getOprType();

        //判断用户的查询类型,商户不区分角色
        if (QueryTypeEnum.MCHNT_QYERY_TYPE.getQueryTypeCode().equals(queryType)) {
            //0-保存活动  1-创建活动 2-修改活动 3-删除活动
            if (OprTypeEnum.EDIT_SAVE.getOprTypeCode().equals(oprType)) {
                //保存草稿
                rglog.info("保存活动流程开始");
                saveMcInfo(xmlTreeUtil, mchntMcManageRequest);
                rglog.info("保存活动流程结束");
            } else if (OprTypeEnum.EDIT_SUBMIT.getOprTypeCode().equals(oprType)) {
                //创建活动
                rglog.info("创建活动流程开始");
                createMcInfo(xmlTreeUtil, mchntMcManageRequest);
                rglog.info("创建活动流程结束");
            } else if (OprTypeEnum.EDIT_DRAFT.getOprTypeCode().equals(oprType)) {
                rglog.info("修改活动流程开始");
                //修改活动,这个操作暂无具体作用,无具体实现
                updateMcInfo(xmlTreeUtil, mchntMcManageRequest);
                rglog.info("修改活动流程结束");
            } else if (OprTypeEnum.MANAGE_DELETE.getOprTypeCode().equals(oprType)) {
                //删除活动
                rglog.info("删除活动流程开始");
                deleteMcInfo(xmlTreeUtil, mchntMcManageRequest);
                rglog.info("删除活动流程结束");
            } else {
                rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                throw new BizException(RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespDesc());
            }
        } else {
            /* 银行、代理商、收银员或用户 */
            rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        mchntMcManageResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        mchntMcManageResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        mchntMcManageResponse.setMcNo(globalMcNo);
        bizResponse.setResult(mchntMcManageResponse);

        return bizResponse;
    }

    /**
     * 生成营销活动编号
     *
     * @param mchntMcInfoBean 活动基本信息对象
     * @return java.lang.String
     * @throws Exception 异常信息
     * @author liujinan
     * @date 020/6/11 14:57
     */
    private String generateNewMcNo(MchntMcInfoBean mchntMcInfoBean) throws Exception {

        // MC+2位营销活动类型+1位出资方+8位活动起始日期+8位活动截止日期+11位sequence
        MompSequenceMapper mompSequenceMapper = new MompSequenceMapperImpl();

        String mcNoSuffix = mompSequenceMapper.getMompNextMaNoSeq();

        String mcNo = "MC" + mchntMcInfoBean.getMcType() + mchntMcInfoBean.getSponsor() + mchntMcInfoBean.getMcStartDate() + mchntMcInfoBean.getMcEndDate() + mcNoSuffix;

        return mcNo;
    }

    /**
     * 保存活动
     *
     * @param mchntMcManageRequest 商户营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 17:43
     */
    private void saveMcInfo(XmlTreeUtil xmlTreeUtil, MchntMcManageRequest mchntMcManageRequest) throws Exception {

        rglog.info("保存数据流程开始");
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        //如果没有营销活动编号,则保存数据是完全新增数据的流程，需要生成营销活动编号
        if (StringUtil.isNullorEmpty(globalMcNo)) {
            //如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据
            globalMcNo = generateNewMcNo(mchntMcManageRequest.getMcInfoObj());
            rglog.info("新生成的活动编号MC_NO=<{}>", globalMcNo);
            //全部新增流程，插入数据
            insertAllMcInfo(dbsUtil, mchntMcManageRequest);

        } else {
            //如果保存数据有营销活动编号,则查询数据库营销活动信息
            //如果是减免类营销活动
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                //营销活动信息正式表查询
                TMMcMoneyOffInfo oldTMMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
                //营销活动信息临时表查询
                PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
                TMPlatBizTmp oldPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());

                if (null == oldTMMcMoneyOffInfo || null == oldPlatBizTmp) {
                    rglog.error("当前营销活动<{}>,查询正是表或临时表无数据!", globalMcNo);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                }

                //如果有活动编号上送，查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
                String oldOprId = oldTMMcMoneyOffInfo.getOprId();
                String thisOprId = mchntMcManageRequest.getQueryId();
                if (!oldOprId.equals(thisOprId)) {
                    rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

                if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(oldTMMcMoneyOffInfo.getMcStatus()) ||
                        McStatusEnum.TESTING.getMcStatusCode().equals(oldTMMcMoneyOffInfo.getMcStatus())) {
                    rglog.error("当前营销活动<{}>,活动状态<{}>,不允许保存草稿!", globalMcNo, oldTMMcMoneyOffInfo.getMcStatus());
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                }
                //更新数据
                updateAllMcInfo(dbsUtil, mchntMcManageRequest, oldTMMcMoneyOffInfo);

            } else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
                //营销活动信息正式表查询
                TMMcCouponInfo oldTMMcCouponInfo = (TMMcCouponInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
                //营销活动信息临时表查询
                PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
                TMPlatBizTmp oldPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());

                if (null == oldTMMcCouponInfo || null == oldPlatBizTmp) {
                    rglog.error("当前营销活动<{}>,查询正是表或临时表无数据!", globalMcNo);
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                }

                //如果有活动编号上送，查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
                String oldOprId = oldTMMcCouponInfo.getOprId();
                String thisOprId = mchntMcManageRequest.getQueryId();
                if (!oldOprId.equals(thisOprId)) {
                    rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

                if (!McStatusEnum.DRAFT.getMcStatusCode().equals(oldTMMcCouponInfo.getMcStatus())) {
                    rglog.error("当前营销活动<{}>,活动状态<{}>,不允许保存草稿!", globalMcNo, oldTMMcCouponInfo.getMcStatus());
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                }
                //更新数据库数据
                updateAllMcInfo(dbsUtil, mchntMcManageRequest, oldTMMcCouponInfo);

            } else {
                rglog.error("当前营销活动<{}>,活动类型<{}>,不支持的活动类型!", globalMcNo, globalMcType);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NOT_SUPPORTED_MC_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_MC_TYPE_ERROR.getRespDesc());
            }
        }

        //正常结束数据库事务
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 创建活动
     *
     * @param mchntMcManageRequest 商户营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 17:43
     */
    private void createMcInfo(XmlTreeUtil xmlTreeUtil, MchntMcManageRequest mchntMcManageRequest) throws Exception {

        int returnCode = 0;
        rglog.info("创建活动流程开始");

        TMMcMoneyOffInfo tmMcMoneyOffInfo = null;
        TMPlatBizTmp moneyOffInfoPlatBizTmp = null;

        TMMcCouponInfo tmMcCouponInfo = null;
        TMPlatBizTmp couponInfoPlatBizTmp = null;

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();

        //判断上送的营销活动信息中预算充值方式，如果是1：预先打款，则创建相当于保存草稿，打款完成后由商户服务调用发布接口，打款成功修改活动状态
        String budgetRechargeMethod = mchntMcManageRequest.getMcInfoObj().getBudgetRechargeMethod();
        if (CommonConstant.ONE_COMMON_CONSTANT.equals(budgetRechargeMethod)) {
            rglog.info("将要创建的活动预算充值方式为预先打款，进入保存草稿的流程处理...");
            //直接走保存草稿的流程
            saveMcInfo(xmlTreeUtil, mchntMcManageRequest);
            return;
        }
        rglog.info("将要创建的活动预算充值方式为活动后结算，进入创建活动流程处理...");
        if (!StringUtil.isNullorEmpty(globalMcNo)) {
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                //减免类营销活动信息正式表查询
                tmMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
                //减免类营销活动信息临时表查询
                moneyOffInfoPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());

            } else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
                //卡券类营销活动信息正式表查询
                tmMcCouponInfo = (TMMcCouponInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
                //卡券类营销活动信息临时表查询
                couponInfoPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
            }
        }

        //开启数据库事务
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        if (null == tmMcMoneyOffInfo && null == moneyOffInfoPlatBizTmp && McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)
                || null == tmMcCouponInfo && null == couponInfoPlatBizTmp && McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
            /* 数据库无历史数据，是新增创建营销活动场景，新增数据后直接确认创建(不是保存草稿)
             * 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据；
             * 如果营销活动编号存在，说明是接口调用错误，需要返回失败信息； */
            if (StringUtil.isNullorEmpty(globalMcNo)) {
                //生成营销活动编号
                globalMcNo = generateNewMcNo(mchntMcManageRequest.getMcInfoObj());
                rglog.info("新生成营销活动编号MC_NO=<{}>", globalMcNo);

                //全部创建活动流程，插入数据
                rglog.info("新增创建营销活动流程开始");
                insertAllMcInfo(dbsUtil, mchntMcManageRequest);

            } else {
                rglog.error("营销活动编号存在，数据库未查询到活动信息，当前营销活动<{}>不可创建!", globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
            }

            //更新临时表各状态
            returnCode = platBizTmpMapper.updateTmpAllStatusByPrimaryKey(globalInstId, globalMcNo,
                    AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode(),
                    BizStatusEnum.TMP_STATUS.getBizStatusCode(), BizStatusEnum.NORMAL_STATUS.getBizStatusCode(),
                    McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode());
            if (Database.DBS_SUCCESS != returnCode) {
                //更新临时表中营销活动审批状态失败
                dbsUtil.dbsEndTransaction(false);
                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
            }

            //更新正式表各状态
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                returnCode = mcDetailInfoMapper.updateMcAllStatusByMcNoAndOriStatusAndTableName(TableNameEnum.T_M_MC_MO_INFO.getTableNameCode(), globalInstId, globalMcNo,
                        McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode(),
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode());

                if (Database.DBS_SUCCESS != returnCode) {
                    //更新正式表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            } else {
                returnCode = mcDetailInfoMapper.updateMcAllStatusByMcNoAndOriStatusAndTableName(TableNameEnum.T_M_MC_CP_INFO.getTableNameCode(), globalInstId, globalMcNo,
                        McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode(),
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    //更新正式表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }

            //正常结束数据库事务
            dbsUtil.dbsEndTransaction(true);

        } else if (null != tmMcMoneyOffInfo && null != moneyOffInfoPlatBizTmp && McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)
                || null != tmMcCouponInfo && null != couponInfoPlatBizTmp && McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
            //数据库有历史数据，是已经保存过,本次经过编辑后进行的创建营销活动
            /*修改创建活动场景, 如果营销活动编号不存在，说明数据异常，不可提交审批；
             * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；*/
            if (StringUtil.isNullorEmpty(globalMcNo)) {
                /* 全部更新流程，更新数据 */
                rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
            } else {
                //全部更新流程，更新数据
                if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                    //如果有活动编号上送，查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
                    String oldOprId = "";
                    if (tmMcMoneyOffInfo != null) {
                        oldOprId = tmMcMoneyOffInfo.getOprId();
                    }
                    String thisOprId = mchntMcManageRequest.getQueryId();
                    if (!oldOprId.equals(thisOprId)) {
                        rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                    updateAllMcInfo(dbsUtil, mchntMcManageRequest, tmMcMoneyOffInfo);
                } else {
                    //如果有活动编号上送，查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
                    String oldOprId = "";
                    if (tmMcCouponInfo != null) {
                        oldOprId = tmMcCouponInfo.getOprId();
                    }
                    String thisOprId = mchntMcManageRequest.getQueryId();
                    if (!oldOprId.equals(thisOprId)) {
                        rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                    updateAllMcInfo(dbsUtil, mchntMcManageRequest, tmMcCouponInfo);
                }
            }

            //更新临时表审批状态
            returnCode = platBizTmpMapper.updateTmpAllStatusByPrimaryKey(globalInstId, globalMcNo,
                    AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode(),
                    BizStatusEnum.TMP_STATUS.getBizStatusCode(), BizStatusEnum.NORMAL_STATUS.getBizStatusCode(),
                    McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode());
            if (Database.DBS_SUCCESS != returnCode) {
                //更新临时表中营销活动审批状态失败
                dbsUtil.dbsEndTransaction(false);
                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
            }
            //更新正式表审批状态
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                returnCode = mcDetailInfoMapper.updateMcAllStatusByMcNoAndOriStatusAndTableName(TableNameEnum.T_M_MC_MO_INFO.getTableNameCode(), globalInstId, globalMcNo,
                        McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode(),
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    //新正式表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            } else {
                returnCode = mcDetailInfoMapper.updateMcAllStatusByMcNoAndOriStatusAndTableName(TableNameEnum.T_M_MC_CP_INFO.getTableNameCode(), globalInstId, globalMcNo,
                        McStatusEnum.DRAFT.getMcStatusCode(), McStatusEnum.TESTING.getMcStatusCode(),
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PASSED.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    //更新正式表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }
        } else {
            //营销活动状态异常，不创建营销活动
            rglog.error("营销活动状态异常，不可提交审批, MC_NO=<{}>", globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }
        //注册卡券生成任务
        if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
            rglog.info("注册卡券生成定时任务");
            timingTask(CommonConstant.CP_CREATE_TIME_TASK_NAME, globalTxnDate, "", globalInstId, globalMcNo, dbsUtil);
        }
        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 修改活动
     *
     * @param xmlTreeUtil          内部XML树
     * @param mchntMcManageRequest 商户营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 00:13
     */
    private void updateMcInfo(XmlTreeUtil xmlTreeUtil, MchntMcManageRequest mchntMcManageRequest) throws Exception {
    }

    /**
     * 删除活动
     *
     * @param mchntMcManageRequest 减免类营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 00:53
     */
    private void deleteMcInfo(XmlTreeUtil xmlTreeUtil, MchntMcManageRequest mchntMcManageRequest) throws Exception {

        int returnCode = 0;
        String instId = mchntMcManageRequest.getHeader().getInstId();

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        //营销活动信息正式表查询
        TMMcMoneyOffInfo tmMcMoneyOffInfo = null;
        TMMcCouponInfo tmMcCouponInfo = null;

        if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
            //减免类营销活动信息正式表查询
            tmMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());

        } else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
            //卡券类营销活动信息正式表查询
            tmMcCouponInfo = (TMMcCouponInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
        }

        if (null == tmMcMoneyOffInfo && null == tmMcCouponInfo) {
            //获取营销活动信息失败
            rglog.error("获取营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
        }

        if (null != tmMcMoneyOffInfo && !McStatusEnum.DRAFT.getMcStatusCode().equals(tmMcMoneyOffInfo.getMcStatus()) ||
                null != tmMcCouponInfo && !McStatusEnum.DRAFT.getMcStatusCode().equals(tmMcCouponInfo.getMcStatus())) {
            //营销活动状态异常，不可删除草稿  --> 仅支持草稿类活动删除
            rglog.error("{}}, MC_STATUS=<{}>, MC_NO=<{}>", RespCodeEnum.WRONG_MC_STATUS_TO_DELETE_IS_DRAFT_ERROR.getRespDesc(), tmMcMoneyOffInfo.getMcStatus(), globalMcNo);
            throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_DELETE_IS_DRAFT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_DELETE_IS_DRAFT_ERROR.getRespDesc());
        }

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        String merchantRange, clientRange, mcTimeFlag;

        if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {

            //查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
            String oldOprId = "";
            if (tmMcMoneyOffInfo != null) {
                oldOprId = tmMcMoneyOffInfo.getOprId();
            }
            String thisOprId = mchntMcManageRequest.getQueryId();
            if (!oldOprId.equals(thisOprId)) {
                rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
            }

            merchantRange = tmMcMoneyOffInfo.getMerchantRange();
            clientRange = tmMcMoneyOffInfo.getClientRange();
            mcTimeFlag = tmMcMoneyOffInfo.getMcTimeFlag();

            //删除营销活动信息
            returnCode = mcDetailInfoMapper.deleteMoneyOffMcInfo(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_DATA_ERROR.getRespDesc());
            }

            //删除营销活动规则信息
            McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
            returnCode = mcRuleInfoMapper.deleteMoneyOffRuleInfoListByBank(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespDesc());
            }
        } else {
            //查询数据库存储的原操作主体（商户号），如果和当前不一致，不允许操作
            String oldOprId = tmMcCouponInfo.getOprId();
            String thisOprId = mchntMcManageRequest.getQueryId();
            if (!oldOprId.equals(thisOprId)) {
                rglog.error("活动 <{}>,原查询主体 <{}>,当前操作上送的查询主体<{}>,两者不同，不允许操作!", globalMcNo, oldOprId, thisOprId);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
            }

            merchantRange = tmMcCouponInfo.getMerchantRange();
            clientRange = tmMcCouponInfo.getClientRange();
            mcTimeFlag = tmMcCouponInfo.getMcTimeFlag();
            /* 删除营销活动信息 */
            returnCode = mcDetailInfoMapper.deleteCpMcInfo(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_DATA_ERROR.getRespDesc());
            }

            /* 删除营销活动规则信息 */
            McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
            returnCode = mcRuleInfoMapper.deleteCouponRuleInfoListByBank(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_RULE_DATA_ERROR.getRespDesc());
            }
        }

        //删除营销活动机构信息
        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        returnCode = mcOrgInfoMapper.deleteMcOrgInfoListByBank(instId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_ORG_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DELETE_MC_ORG_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_ORG_DATA_ERROR.getRespDesc());
        }
        //删除营销活动商户信息
        if (CommonConstant.SPECIFIC_MCHNT_LIST.equals(merchantRange)) {
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            returnCode = mcMchntInfoMapper.deleteMcMchntInfoListByBank(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc());
            }
        }
        //删除营销活动用户信息
        if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(clientRange)) {
            McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
            returnCode = mcUserInfoMapper.deleteMcUserInfoListByBank(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_USER_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_USER_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_USER_DATA_ERROR.getRespDesc());
            }
        }

        //删除营销活动时间信息
        if (CommonConstant.SPECIFIC_TIME_SUPPORT.equals(mcTimeFlag)) {
            McTimeInfoMapper mcTimeInfoMapper = new McTimeInfoMapperImpl();
            returnCode = mcTimeInfoMapper.deleteMcTimeInfoListByBank(instId, globalMcNo);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_TIME_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DELETE_MC_TIME_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_TIME_DATA_ERROR.getRespDesc());
            }
        }

        //删除营销活动产品信息
        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        returnCode = mcProductInfoMapper.deleteMcProductInfoListByBank(instId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_MC_PRODUCT_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DELETE_MC_PRODUCT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_PRODUCT_DATA_ERROR.getRespDesc());
        }

        //删除临时表营销活动所有信息
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        returnCode = platBizTmpMapper.deleteTmpMcDataByMcNo(instId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc());
        }

        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 减免类营销活动信息数据库实体类和接口实体类数据转换
     *
     * @param mchntMcInfoBean 活动基本信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMoneyOffInfo 减免类营销活动信息表
     * @author liujinan
     * @date 2020/6/11 15:18
     */
    private TMMcMoneyOffInfo convertMoneyOffMcInfo(MchntMcInfoBean mchntMcInfoBean) {

        // 检查上传字段 不能为负数
        checkMcInfoObjFieldHasNegativeNumber(mchntMcInfoBean);

        TMMcMoneyOffInfo mcMoneyOffInfo = new TMMcMoneyOffInfo();
        try {
            /* 法人机构号 */
            mcMoneyOffInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMoneyOffInfo.setMcNo(globalMcNo);
            /* 营销活动名称 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcName())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcName(mchntMcInfoBean.getMcName());
            }
            /* 营销活动类型 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcType())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcType(mchntMcInfoBean.getMcType());
            }
            /* 营销活动状态 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcStatus())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcStatus(mchntMcInfoBean.getMcStatus());
            }
            /* 活动起始日期 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcStartDate())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcStartDate(mchntMcInfoBean.getMcStartDate());
            }
            /* 活动截止日期 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcEndDate())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcEndDate(mchntMcInfoBean.getMcEndDate());
            }
            /* 活动结束日期 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcActualEndDate())) {
                /* 不需要计算，直接使用活动结束日期*/
                mcMoneyOffInfo.setMcActualEndDate(mchntMcInfoBean.getMcEndDate());
            } else {
                /* 不需要计算，直接使用接口上送内容 */
                mcMoneyOffInfo.setMcActualEndDate(mchntMcInfoBean.getMcActualEndDate());
            }
            /* 活动时间标志 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcTimeFlag())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMcTimeFlag(mchntMcInfoBean.getMcTimeFlag());
            }
            /* 出资方 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getSponsor())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setSponsor(mchntMcInfoBean.getSponsor());
            }
            /* 参与次数限制 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getRestriction())) {
                mcMoneyOffInfo.setRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                mcMoneyOffInfo.setRestriction(mchntMcInfoBean.getRestriction());
            }
            /* 客户范围 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getClientRange())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setClientRange(mchntMcInfoBean.getClientRange());
            }
            /* 商户范围 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMerchantRange())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setMerchantRange(mchntMcInfoBean.getMerchantRange());
            }
            /* 预算充值方式 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getBudgetRechargeMethod())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setBudgetRechargeMethod(mchntMcInfoBean.getBudgetRechargeMethod());
            }
            /* 预算 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getBudget())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcMoneyOffInfo.setBudget(MompAmountUtil.getTwoDecimal(mchntMcInfoBean.getBudget()));
            }
//        /* 银行出资预算 */
//        if(StringUtil.isNullorEmpty(mchntMcInfoBean.getBankBudget())) {
//            tmMcMoneyOffInfo.setBankBudget(CommonConstant.ZERO_AMOUNT);
//        } else {
//            tmMcMoneyOffInfo.setBankBudget(MompAmountUtil.getTwoDecimal(mchntMcInfoBean.getBankBudget()));
//        }
            /* 预期参与商户数量 */

            mcMoneyOffInfo.setExpectMchntQty(CommonConstant.ONE_COMMON_CONSTANT);
            /* 银行出资比例 银行出资预算*/

            mcMoneyOffInfo.setBankBudgetRatio(CommonConstant.ZERO_COMMON_CONSTANT);
            mcMoneyOffInfo.setBankBudget(CommonConstant.ZERO_AMOUNT);

            /* 审批状态-待提交审批状态 */
            mcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            mcMoneyOffInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMoneyOffInfo.setCreateTime(globalTimeStamp);
            /* 最后修改人 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getLastOprId())) {
                mcMoneyOffInfo.setLastOprId(mchntMcInfoBean.getLastOprId());
            }
            mcMoneyOffInfo.setUpdateTime(globalTimeStamp);
            /* 审批拒绝原因 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getAuditRefuseReason())) {
                mcMoneyOffInfo.setAuditRefuseReason(mchntMcInfoBean.getAuditRefuseReason());
            }
            /* 发布拒绝原因 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getPublishRefuseReason())) {
                mcMoneyOffInfo.setPublishRefuseReason(mchntMcInfoBean.getPublishRefuseReason());
            }
            /* 备用字段1 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRemark1())) {
                mcMoneyOffInfo.setRemark1(mchntMcInfoBean.getRemark1());
            }
            /* 备用字段2 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRemark2())) {
                mcMoneyOffInfo.setRemark2(mchntMcInfoBean.getRemark2());
            }
            /* 备用字段3 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRemark3())) {
                mcMoneyOffInfo.setRemark3(mchntMcInfoBean.getRemark3());
            }
            /* 备用字段4 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRemark4())) {
                mcMoneyOffInfo.setRemark4(mchntMcInfoBean.getRemark4());
            }
            /* 备用字段5 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRemark5())) {
                mcMoneyOffInfo.setRemark5(mchntMcInfoBean.getRemark5());
            }
            /* 创建机构 */
            if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                mcMoneyOffInfo.setCrtOrgId(globalQueryOrgId);
            }

            /* 活动发布批量任务状态 */
            mcMoneyOffInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_SUCCESS);
        } catch (Exception e) {
            rglog.error("转换营销活动信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMoneyOffInfo;
    }

    /**
     * 营销活动机构信息数据库实体类和接口实体类数据转换
     *
     * @param mcOrgInfoBean 营销活动机构信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcOrgInfo 营销活动机构信息表
     * @author liujinan
     * @date 22020/6/11 21:11
     */
    private TMMcOrgInfo convertMcOrgInfo(McOrgInfoBean mcOrgInfoBean) {
        TMMcOrgInfo mcOrgInfo = new TMMcOrgInfo();
        try {
            /* 法人机构号 */
            mcOrgInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcOrgInfo.setMcNo(globalMcNo);
            /* 机构编号 */
            mcOrgInfo.setOrgId(mcOrgInfoBean.getOrgId());
            /* 机构层级 */
            mcOrgInfo.setOrgHierarchy(mcOrgInfoBean.getOrgHierarchy());
            /* 机构名称 */
            mcOrgInfo.setOrgName(mcOrgInfoBean.getOrgName());
            /* 创建人 */
            mcOrgInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcOrgInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcOrgInfo;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author liujinan
     * @date 22020/6/11 21:10
     */
    private TMMcMchntInfo convertMcMchntInfo(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate("");
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动用户规则信息数据库实体类和接口实体类数据转换
     *
     * @param mcUserInfoBean 营销活动用户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcUserInfo 营销活动用户信息表
     * @author liujinan
     * @date 22020/6/11 21:09
     */
    private TMMcUserInfo convertMcUserInfo(McUserInfoBean mcUserInfoBean) {
        TMMcUserInfo mcUserInfo = new TMMcUserInfo();
        try {
            /* 法人机构号 */
            mcUserInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcUserInfo.setMcNo(globalMcNo);
            /* 账户类型 */
            mcUserInfo.setAcctType(mcUserInfoBean.getAcctType());
            /* 账户 */
            mcUserInfo.setAcctNo(mcUserInfoBean.getAcctNo());
            /* 账户标志 */
            mcUserInfo.setAcctFlag(CommonConstant.ACCT_FLAG_NORMAL);
            /* 会员ID */
            mcUserInfo.setMemberId(mcUserInfoBean.getMemberId());
            /* 创建人 */
            mcUserInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcUserInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcUserInfo;
    }

    /**
     * 营销活动测试账号信息数据库实体类和接口实体类数据转换
     *
     * @param testAcctInfoBean 测试账号信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcUserInfo 营销活动用户信息表
     * @author liujinan
     * @date 22020/6/15 21:09
     */
    private TMMcUserInfo convertTestAcctInfo(TestAcctInfoBean testAcctInfoBean) {
        TMMcUserInfo mcUserInfo = new TMMcUserInfo();
        try {
            /* 法人机构号 */
            mcUserInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcUserInfo.setMcNo(globalMcNo);
            /* 账户类型 0-手机号 1-银行卡号*/
            mcUserInfo.setAcctType(CommonConstant.MEMBERTYPE_IPHONE);
            /* 账户 */
            mcUserInfo.setAcctNo(testAcctInfoBean.getTestAcctNo());
            /* 账户标志 */
            mcUserInfo.setAcctFlag(CommonConstant.ACCT_FLAG_TESTING);
            /* 会员ID */
            mcUserInfo.setMemberId(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 创建人 */
            mcUserInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcUserInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换测试账号信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcUserInfo;
    }

    /**
     * 营销活动时间规则信息数据库实体类和接口实体类数据转换
     *
     * @param mcTimeInfoBean 营销活动事件对象
     * @return cc.rengu.igas.momp.common.entity.TMMcTimeInfo 营销活动时间信息表
     * @author liujinan
     * @date 22020/6/11 21:09
     */
    private TMMcTimeInfo convertMcTimeInfo(McTimeInfoBean mcTimeInfoBean) {
        TMMcTimeInfo mcTimeInfo = new TMMcTimeInfo();
        try {
            /* 法人机构号 */
            mcTimeInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcTimeInfo.setMcNo(globalMcNo);
            /* 顺序号 */
            mcTimeInfo.setRuleIndex(mcTimeInfoBean.getRuleIndex());
            /* 星期一日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagMonday())) {
                mcTimeInfo.setFlagMonday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagMonday(mcTimeInfoBean.getFlagMonday());
            }
            /* 星期二日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagTuesday())) {
                mcTimeInfo.setFlagTuesday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagTuesday(mcTimeInfoBean.getFlagTuesday());
            }
            /* 星期三日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagWednesday())) {
                mcTimeInfo.setFlagWednesday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagWednesday(mcTimeInfoBean.getFlagWednesday());
            }
            /* 星期四日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagThursday())) {
                mcTimeInfo.setFlagThursday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagThursday(mcTimeInfoBean.getFlagThursday());
            }
            /* 星期五日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagFriday())) {
                mcTimeInfo.setFlagFriday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagFriday(mcTimeInfoBean.getFlagFriday());
            }
            /* 星期六日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagSaturday())) {
                mcTimeInfo.setFlagSaturday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagSaturday(mcTimeInfoBean.getFlagSaturday());
            }
            /* 星期日日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagSunday())) {
                mcTimeInfo.setFlagSunday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagSunday(mcTimeInfoBean.getFlagSunday());
            }
            /* 起始时间 */
            mcTimeInfo.setStartTime(mcTimeInfoBean.getStartTime());
            /* 结束时间 */
            mcTimeInfo.setEndTime(mcTimeInfoBean.getEndTime());
            /* 创建人 */
            mcTimeInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcTimeInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcTimeInfo;
    }

    /**
     * 减免类营销活动规则信息数据库实体类和接口实体类数据转换
     *
     * @param mchntMcRuleInfoBean 营销活动规则信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMoneyOffRuleInfo 减免类营销活动规则表
     * @author liujinan
     * @date 22020/6/11 21:07
     */
    private TMMcMoneyOffRuleInfo convertMoneyOffMcRuleInfo(MchntMcRuleInfoBean mchntMcRuleInfoBean) {

        // 检查上传字段 不能为负数
        checkRuleInfoFieldHasNegativeNumber(mchntMcRuleInfoBean);

        TMMcMoneyOffRuleInfo moneyOffRuleInfo = new TMMcMoneyOffRuleInfo();

        try {
            /* 法人机构号 */
            moneyOffRuleInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            moneyOffRuleInfo.setMcNo(globalMcNo);
            /* 顺序号  */
            moneyOffRuleInfo.setRuleIndex(mchntMcRuleInfoBean.getRuleIndex());
            /* 活动门槛 */
            moneyOffRuleInfo.setCriteria(mchntMcRuleInfoBean.getCriteria());
            /* 优惠力度下限 */
            moneyOffRuleInfo.setDiscountFloor(mchntMcRuleInfoBean.getDiscountFloor());
            /* 优惠力度上限 */
            moneyOffRuleInfo.setDiscountCelling(mchntMcRuleInfoBean.getDiscountCelling());
            /* 总优惠数量 */
            moneyOffRuleInfo.setDiscountQuantity(mchntMcRuleInfoBean.getDiscountQuantity());
            /* 单次优惠限制 */
            moneyOffRuleInfo.setDiscountLimit(mchntMcRuleInfoBean.getDiscountLimit());
            /* 优惠总预算 */
            moneyOffRuleInfo.setBudget(mchntMcRuleInfoBean.getBudget());
            /* 单日消耗预算 */
            moneyOffRuleInfo.setBudgetDayLimit(mchntMcRuleInfoBean.getBudgetDayLimit());
            /* 创建人 */
            moneyOffRuleInfo.setOprId(globalOprId);
            /* 创建时间 */
            moneyOffRuleInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动规则信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return moneyOffRuleInfo;
    }

    /**
     * 营销活动支付产品信息数据库实体类和接口实体类数据转换
     *
     * @param mcProductInfoBean 营销活动产品对象
     * @return cc.rengu.igas.momp.common.entity.TMMcProductInfo 营销活动产品信息表
     * @author liujinan
     * @date 22020/6/11 21:06
     */
    private TMMcProductInfo convertMcProductInfo(McProductInfoBean mcProductInfoBean) {
        TMMcProductInfo mcProductInfo = new TMMcProductInfo();
        try {
            /* 法人机构号 */
            mcProductInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcProductInfo.setMcNo(globalMcNo);
            /* 业务产品代码 */
            mcProductInfo.setBizProdCode(mcProductInfoBean.getBizProdCode());
            /* 创建人 */
            mcProductInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcProductInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动支付产品信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcProductInfo;
    }

    /**
     * 更新营销活动信息
     *
     * @param mchntMcManageRequest 商户营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 00:13
     */
    private void updateAllMcInfo(DbsUtil dbsUtil, MchntMcManageRequest mchntMcManageRequest, Object oldTMMcInfo) throws Exception {

        String clientRange, mcTimeFlag;

        // 删除指定营销活动编号的所有草稿状态的数据数据
        int returnCode = 0;
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        returnCode = platBizTmpMapper.deleteTmpMcDataByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("{}, RETURN_CODE=<{}>, MC_NO=<{}>", RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc(), returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc());
        }

        if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
            //减免类营销活动基本信息新增
            /* 营销活动信息更新 */
            TMMcMoneyOffInfo tmMcMoneyOffInfo = convertMoneyOffMcInfo(mchntMcManageRequest.getMcInfoObj());
            deleteMoMcInfo(dbsUtil);

            tmMcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());//待提交审批
            tmMcMoneyOffInfo.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());//草稿
            insertMoMcInfo(dbsUtil, tmMcMoneyOffInfo);

            TMPlatBizTmp mcMoneyOffInfoPlatBizTmp = convertMoMcInfoToTmp(tmMcMoneyOffInfo);
            insertTmpMoMcInfo(dbsUtil, mcMoneyOffInfoPlatBizTmp);

            /* 营销活动规则信息更新 */
            List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList = mchntMcManageRequest.getRuleInfoList().stream().map(this::convertMoneyOffMcRuleInfo).collect(Collectors.toList());
            deleteMcMoRuleInfo(dbsUtil);
            insertMcMoRuleInfo(dbsUtil, mcMoneyOffRuleInfoList);

            List<TMPlatBizTmp> tmpMoMcRuleList = mcMoneyOffRuleInfoList.stream().map(this::convertMoMcRuleInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMoMcRuleList);

            clientRange = tmMcMoneyOffInfo.getClientRange();
            mcTimeFlag = tmMcMoneyOffInfo.getMcTimeFlag();
        } else {
            /* 营销活动信息更新 */
            TMMcCouponInfo tmMcCouponInfo = convertCouponMcInfo(mchntMcManageRequest.getMcInfoObj());
            deleteCpMcInfo(dbsUtil);

            tmMcCouponInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());//待提交审批
            tmMcCouponInfo.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());//草稿
            insertCpMcInfo(dbsUtil, tmMcCouponInfo);

            TMPlatBizTmp tmMcCouponInfoPlatBizTmp = convertCpMcInfoToTmp(tmMcCouponInfo);
            insertTmpCpMcInfo(dbsUtil, tmMcCouponInfoPlatBizTmp);

            /* 营销活动规则信息更新 */
            List<TMMcCouponRuleInfo> mcCouponRuleInfoList = mchntMcManageRequest.getRuleInfoList().stream().map(this::convertCouponMcRuleInfo).collect(Collectors.toList());
            deleteCouponRuleInfoList(dbsUtil);
            insertMcCouponRuleInfo(dbsUtil, mcCouponRuleInfoList);

            List<TMPlatBizTmp> tmpCpMcRuleList = mcCouponRuleInfoList.stream().map(this::convertCpMcRuleInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpCpMcRuleList);

            clientRange = tmMcCouponInfo.getClientRange();
            mcTimeFlag = tmMcCouponInfo.getMcTimeFlag();
        }

        /* 营销活动机构信息更新 */
        deleteMcOrgInfo(dbsUtil);
        List<TMMcOrgInfo> mcOrgInfoList = globalOrgInfoList.stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);

        /* 营销活动商户信息更新 */
        deleteMcMchntInfo(dbsUtil);
        List<TMMcMchntInfo> mcMchntInfoList = mchntMcManageRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
        insertMcMchntInfo(dbsUtil, mcMchntInfoList);
        List<TMPlatBizTmp> tmpMchntList = mcMchntInfoList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);


        /* 营销活动用户信息更新 */
        if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(clientRange)) {
            //删除原有的数据
            deleteMcUserInfo(dbsUtil);
            List<TMMcUserInfo> mcUserInfoList = mchntMcManageRequest.getUserInfoList().stream().map(this::convertMcUserInfo).collect(Collectors.toList());
            //测试账号信息
            List<TMMcUserInfo> testAccountInfoList = mchntMcManageRequest.getTestAcctInfoList().stream().map(this::convertTestAcctInfo).collect(Collectors.toList());
            mcUserInfoList.addAll(testAccountInfoList);

            insertMcUserInfo(dbsUtil, mcUserInfoList);

            List<TMPlatBizTmp> tmpUserList = mcUserInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);
        } else {
            //删除原有的数据
            deleteMcUserInfo(dbsUtil);
            //测试账号信息
            List<TMMcUserInfo> testAccountInfoList = mchntMcManageRequest.getTestAcctInfoList().stream().map(this::convertTestAcctInfo).collect(Collectors.toList());
            insertMcUserInfo(dbsUtil, testAccountInfoList);
            List<TMPlatBizTmp> tmpUserList = testAccountInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);
        }

        /* 营销活动时间信息更新 */
        if (CommonConstant.SPECIFIC_TIME_SUPPORT.equals(mcTimeFlag)) {
            List<TMMcTimeInfo> mcTimeInfoList = mchntMcManageRequest.getTimeInfoList().stream().map(this::convertMcTimeInfo).collect(Collectors.toList());
            deleteMcTimeInfo(dbsUtil);
            insertMcTimeInfo(dbsUtil, mcTimeInfoList);

            List<TMPlatBizTmp> tmpTimeList = mcTimeInfoList.stream().map(this::convertMcTimeInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpTimeList);
        } else {
            deleteMcTimeInfo(dbsUtil);
        }

        /* 营销活动产品信息更新 */
        deleteMcProductInfo(dbsUtil);
        List<TMMcProductInfo> mcProductInfoList = mchntMcManageRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);
    }

    /**
     * 新增营销活动信息
     *
     * @param dbsUtil              数据为操作工具类
     * @param mchntMcManageRequest 商户营销活动管理接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 020/6/11 18:48
     */
    private void insertAllMcInfo(DbsUtil dbsUtil, MchntMcManageRequest mchntMcManageRequest) throws Exception {

        String merchantRange, clientRange, mcTimeFlag;

        if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
            //减免类营销活动基本信息新增
            TMMcMoneyOffInfo mcMoneyOffInfo = convertMoneyOffMcInfo(mchntMcManageRequest.getMcInfoObj());
            mcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());//待提交审批
            mcMoneyOffInfo.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());//草稿

            merchantRange = mcMoneyOffInfo.getMerchantRange();
            clientRange = mcMoneyOffInfo.getClientRange();
            mcTimeFlag = mcMoneyOffInfo.getMcTimeFlag();

            insertMoMcInfo(dbsUtil, mcMoneyOffInfo);
            TMPlatBizTmp tmPlatBizTmp = convertMoMcInfoToTmp(mcMoneyOffInfo);
            insertTmpMoMcInfo(dbsUtil, tmPlatBizTmp);

            //减免类营销活动规则信息新增
            List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList = mchntMcManageRequest.getRuleInfoList().stream().map(this::convertMoneyOffMcRuleInfo).collect(Collectors.toList());
            insertMcMoRuleInfo(dbsUtil, mcMoneyOffRuleInfoList);
            List<TMPlatBizTmp> tmpMoMcRuleList = mcMoneyOffRuleInfoList.stream().map(this::convertMoMcRuleInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMoMcRuleList);
        } else {
            //卡券类营销活动基本信息新增
            TMMcCouponInfo mcCouponInfo = convertCouponMcInfo(mchntMcManageRequest.getMcInfoObj());
            mcCouponInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());//待提交审批
            mcCouponInfo.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());//草稿

            merchantRange = mcCouponInfo.getMerchantRange();
            clientRange = mcCouponInfo.getClientRange();
            mcTimeFlag = mcCouponInfo.getMcTimeFlag();

            insertCpMcInfo(dbsUtil, mcCouponInfo);
            TMPlatBizTmp tmPlatBizTmp = convertCpMcInfoToTmp(mcCouponInfo);
            insertTmpCpMcInfo(dbsUtil, tmPlatBizTmp);

            //卡券类营销活动规则信息新增
            List<TMMcCouponRuleInfo> mcCouponRuleInfoList = mchntMcManageRequest.getRuleInfoList().stream().map(this::convertCouponMcRuleInfo).collect(Collectors.toList());
            insertMcCouponRuleInfo(dbsUtil, mcCouponRuleInfoList);
            List<TMPlatBizTmp> tmpCpMcRuleList = mcCouponRuleInfoList.stream().map(this::convertCpMcRuleInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpCpMcRuleList);
        }

        //营销活动机构信息新增
        List<TMMcOrgInfo> mcOrgInfoList = globalOrgInfoList.stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);

        //营销活动商户信息新增
        if (CommonConstant.SPECIFIC_MCHNT_LIST.equals(merchantRange)) {
            List<TMMcMchntInfo> mcMchntInfoList = mchntMcManageRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
            insertMcMchntInfo(dbsUtil, mcMchntInfoList);
            List<TMPlatBizTmp> tmpMchntList = mcMchntInfoList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);
        }

        //营销活动用户信息新增
        if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(clientRange)) {
            List<TMMcUserInfo> mcUserInfoList = mchntMcManageRequest.getUserInfoList().stream().map(this::convertMcUserInfo).collect(Collectors.toList());
            //测试账号信息
            List<TMMcUserInfo> testAccountInfoList = mchntMcManageRequest.getTestAcctInfoList().stream().map(this::convertTestAcctInfo).collect(Collectors.toList());
            mcUserInfoList.addAll(testAccountInfoList);

            insertMcUserInfo(dbsUtil, mcUserInfoList);
            List<TMPlatBizTmp> tmpUserList = mcUserInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);
        } else {
            //测试账号信息
            List<TMMcUserInfo> testAccountInfoList = mchntMcManageRequest.getTestAcctInfoList().stream().map(this::convertTestAcctInfo).collect(Collectors.toList());
            insertMcUserInfo(dbsUtil, testAccountInfoList);
            List<TMPlatBizTmp> tmpUserList = testAccountInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);
        }

        //营销活动时间信息新增
        if (CommonConstant.SPECIFIC_TIME_SUPPORT.equals(mcTimeFlag)) {
            List<TMMcTimeInfo> mcTimeInfoList = mchntMcManageRequest.getTimeInfoList().stream().map(this::convertMcTimeInfo).collect(Collectors.toList());
            insertMcTimeInfo(dbsUtil, mcTimeInfoList);
            List<TMPlatBizTmp> tmpTimeList = mcTimeInfoList.stream().map(this::convertMcTimeInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpTimeList);
        }

        //营销活动产品信息新增
        List<TMMcProductInfo> mcProductInfoList = mchntMcManageRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);

    }

    /**
     * 插入减免类营销活动基本信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcMoneyOffInfo 减免类营销活动信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 16:35
     */
    private void insertMoMcInfo(DbsUtil dbsUtil, TMMcMoneyOffInfo mcMoneyOffInfo) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.insertSingleMoneyOffMcInfo(mcMoneyOffInfo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 减免类营销活动基本信息插入临时表中
     *
     * @param dbsUtil      数据库操作工具类
     * @param tmPlatBizTmp 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 15:39
     */
    private void insertTmpMoMcInfo(DbsUtil dbsUtil, TMPlatBizTmp tmPlatBizTmp) throws Exception {

        /* 数据入库 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMcInfoByBank(tmPlatBizTmp);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 减免类营销活动信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param mcMoneyOffInfo 减免类营销活动信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 11:49
     */
    private TMPlatBizTmp convertMoMcInfoToTmp(TMMcMoneyOffInfo mcMoneyOffInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        /* 法人机构标识 */
        tmPlatBizTmp.setInstId(mcMoneyOffInfo.getInstId());
        /* 营销活动编号 */
        tmPlatBizTmp.setMcNo(mcMoneyOffInfo.getMcNo());
        /* 操作菜单 */
        tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
        /* 操作菜单名 */
        tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
        /* 操作表中文名 */
        tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MO_INFO.getTableNameDesc());
        /* 操作表英文名 */
        tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
        /* 操作 */
        tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
        /* 数据域1 - 拼接JSON字符串 */
        tmPlatBizTmp.setBizData1(JsonOperation.packMoMcInfoTmpBizData1(mcMoneyOffInfo, rglog));
        /* 状态 */
        tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
        /* 营销活动状态 */
        tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
        /* 审批状态 */
        tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
        /* 创建人 */
        tmPlatBizTmp.setOprId(globalOprId);
        /* 创建时间 */
        tmPlatBizTmp.setCreateTime(globalTimeStamp);

        return tmPlatBizTmp;

    }

    /**
     * 插入营销活动机构信息表
     *
     * @param dbsUtil       数据库操作工具类
     * @param mcOrgInfoList 营销活动机构信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 16:38
     */
    private void insertMcOrgInfo(DbsUtil dbsUtil, List<TMMcOrgInfo> mcOrgInfoList) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.insertMcOrgInfoListByBank(mcOrgInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动机构信息插入临时表中
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 22:17
     */
    private void insertMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMultiMcDetialInfoByBank(tmPlatBizTmpList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动机构信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcOrgInfo 营销活动机构信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:12
     */
    private TMPlatBizTmp convertMcOrgInfoToTmp(TMMcOrgInfo tmMcOrgInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        /* 法人机构标识 */
        tmPlatBizTmp.setInstId(tmMcOrgInfo.getInstId());
        /* 营销活动编号 */
        tmPlatBizTmp.setMcNo(tmMcOrgInfo.getMcNo());
        /* 机构编号 */
        tmPlatBizTmp.setOrgId(tmMcOrgInfo.getOrgId());
        /* 操作菜单 */
        tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
        /* 操作菜单名 */
        tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
        /* 操作表中文名 */
        tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameDesc());
        /* 操作表英文名 */
        tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameCode());
        /* 操作 */
        tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
        /* 数据域1 - 拼接JSON字符串 */
        tmPlatBizTmp.setBizData1(JsonOperation.packMcOrgInfoTmpBizData1(tmMcOrgInfo, rglog));
        /* 状态 */
        tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
        /* 营销活动状态 */
        tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
        /* 审批状态 */
        tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
        /* 创建人 */
        tmPlatBizTmp.setOprId(globalOprId);
        /* 创建时间 */
        tmPlatBizTmp.setCreateTime(globalTimeStamp);

        return tmPlatBizTmp;

    }

    /**
     * 插入营销活动商户信息
     *
     * @param dbsUtil         数据库操作工具类
     * @param mcMchntInfoList 营销活动商户信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:05
     */
    private void insertMcMchntInfo(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(mcMchntInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动商户信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmp(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate("");
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动用户信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcUserInfoList 营销活动用户信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:11
     */
    private void insertMcUserInfo(DbsUtil dbsUtil, List<TMMcUserInfo> mcUserInfoList) throws Exception {

        McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
        int returnCode = mcUserInfoMapper.insertMcUserInfoListByBank(mcUserInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动用户信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动用户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcUserInfo 营销活动用户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:35
     */
    private TMPlatBizTmp convertMcUserInfoToTmp(TMMcUserInfo tmMcUserInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcUserInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcUserInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_USER_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_USER_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcUserInfoTmpBizData1(tmMcUserInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动时间信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcTimeInfoList 营销活动时间信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:13
     */
    private void insertMcTimeInfo(DbsUtil dbsUtil, List<TMMcTimeInfo> mcTimeInfoList) throws Exception {

        McTimeInfoMapper mcTimeInfoMapper = new McTimeInfoMapperImpl();
        int returnCode = mcTimeInfoMapper.insertMcTimeInfoListByBank(mcTimeInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动时间信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动时间信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcTimeInfo TMMcTimeInfo
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:47
     */
    private TMPlatBizTmp convertMcTimeInfoToTmp(TMMcTimeInfo tmMcTimeInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcTimeInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcTimeInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_TIME_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_TIME_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcTimeInfoTmpBizData1(tmMcTimeInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动减免类规则信息
     *
     * @param dbsUtil                数据库操作工具类
     * @param mcMoneyOffRuleInfoList 减免类营销活动规则表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:15
     */
    private void insertMcMoRuleInfo(DbsUtil dbsUtil, List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.insertMoneyOffRuleInfoListByBank(mcMoneyOffRuleInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动减免类规则信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMoneyOffRuleInfo 减免类营销活动规则表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:49
     */
    private TMPlatBizTmp convertMoMcRuleInfoToTmp(TMMcMoneyOffRuleInfo tmMcMoneyOffRuleInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMoneyOffRuleInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMoneyOffRuleInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MO_RULE_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MO_RULE_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMoMcRuleInfoTmpBizData1(tmMcMoneyOffRuleInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动产品信息
     *
     * @param dbsUtil           数据库操作工具类
     * @param mcProductInfoList 营销活动产品信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:08
     */
    private void insertMcProductInfo(DbsUtil dbsUtil, List<TMMcProductInfo> mcProductInfoList) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.insertMcProductInfoListByBank(mcProductInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动产品信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动产品信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcProductInfo 营销活动产品信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:49
     */
    private TMPlatBizTmp convertMcProdInfoToTmp(TMMcProductInfo tmMcProductInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcProductInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcProductInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcProdInfoTmpBizData1(tmMcProductInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 删除减免类营销活动基本信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 16:35
     */
    private void deleteMoMcInfo(DbsUtil dbsUtil) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.deleteMoneyOffMcInfo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动机构信息表
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 16:38
     */
    private void deleteMcOrgInfo(DbsUtil dbsUtil) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.deleteMcOrgInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动机构信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:05
     */
    private void deleteMcMchntInfo(DbsUtil dbsUtil) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMcMchntInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动用户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:11
     */
    private void deleteMcUserInfo(DbsUtil dbsUtil) throws Exception {

        McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
        int returnCode = mcUserInfoMapper.deleteMcUserInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动用户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动时间信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:13
     */
    private void deleteMcTimeInfo(DbsUtil dbsUtil) throws Exception {

        McTimeInfoMapper mcTimeInfoMapper = new McTimeInfoMapperImpl();
        int returnCode = mcTimeInfoMapper.deleteMcTimeInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动时间信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动减免类规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:15
     */
    private void deleteMcMoRuleInfo(DbsUtil dbsUtil) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.deleteMoneyOffRuleInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动减免类规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动产品信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/11 18:08
     */
    private void deleteMcProductInfo(DbsUtil dbsUtil) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.deleteMcProductInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动产品信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }


    /**
     * 卡券类营销活动信息数据库实体类和接口实体类数据转换
     *
     * @param mchntMcInfoBean 活动基本信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcCouponInfo 卡券类营销活动信息表
     * @author liujinan
     * @date 2020/6/12
     */
    private TMMcCouponInfo convertCouponMcInfo(MchntMcInfoBean mchntMcInfoBean) {

        // 检查上传字段 不能为负数
        checkMcInfoObjFieldHasNegativeNumber(mchntMcInfoBean);

        TMMcCouponInfo mcCouponInfo = new TMMcCouponInfo();
        try {
            /* 法人机构号 */
            mcCouponInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcCouponInfo.setMcNo(globalMcNo);
            /* 营销活动名称 */
            mcCouponInfo.setMcName(mchntMcInfoBean.getMcName());
            /* 营销活动类型 */
            mcCouponInfo.setMcType(mchntMcInfoBean.getMcType());
            /* 营销活动状态 */
            mcCouponInfo.setMcStatus(mchntMcInfoBean.getMcStatus());
            /* 活动起始日期 */
            mcCouponInfo.setMcStartDate(mchntMcInfoBean.getMcStartDate());
            /* 活动截止日期 */
            mcCouponInfo.setMcEndDate(mchntMcInfoBean.getMcEndDate());
            /* 活动结束日期 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getMcActualEndDate())) {
                /* 需要根据卡券有效期计算营销活动实际结束日期 */
                if (CommonConstant.COUPON_FIXED_DATE.equals(mchntMcInfoBean.getCouponDateFlag())) {

                    /* 卡券有效期是绝对日期范围 */

                    /* 比较营销活动结束日期和卡券有效结束日期,选取最靠后的日期作为实际结束日期 */
                    /* 卡券有效结束日期 */
                    if (StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponEndDate())) {
                        throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                    } else {
                        String mcDate = mchntMcInfoBean.getMcEndDate();
                        String couponDate = mchntMcInfoBean.getCouponEndDate();
                        if (CommonConstant.ZERO >= DateUtil.compareDate(mcDate, couponDate)) {
                            /* 营销活动结束日期小于等于卡券有效结束日期,使用卡券有效结束日期作为营销活动实际结束日期 */
                            mcCouponInfo.setMcActualEndDate(mchntMcInfoBean.getCouponEndDate());
                        } else {
                            /* 营销活动结束日期大于卡券有效结束日期,使用营销活动结束日期作为营销活动实际结束日期 */
                            mcCouponInfo.setMcActualEndDate(mchntMcInfoBean.getMcEndDate());
                        }
                    }

                } else {
                    /* 卡券有效期是相对日期范围 */

                    /* 根据卡券相对周期和营销活动结束日期计算营销活动实际结束日期 */
                    /* 卡券相对周期 */
                    if (StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponPeriod())) {
                        throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                    } else {
                        String mcEndDate = mchntMcInfoBean.getMcEndDate();
                        int dayPeriod = Integer.parseInt(mchntMcInfoBean.getCouponPeriod());

                        /* 根据卡券生效时间进一步计算卡券有效期 */
                        /* 卡券生效时间 */
                        if (StringUtil.isNullorEmpty(mchntMcInfoBean.getAvailableDate())) {
                            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                        } else {
                            if (CommonConstant.COUPON_NEXT_DAY_AVAILABLE.equals(mchntMcInfoBean.getAvailableDate())) {
                                /* 卡券领取后第二天生效 */
                                dayPeriod++;

                                mcCouponInfo.setMcActualEndDate(DateUtil.getBaseDateOffsetDay(mcEndDate, dayPeriod));
                            } else {
                                mcCouponInfo.setMcActualEndDate(DateUtil.getBaseDateOffsetDay(mcEndDate, dayPeriod));
                            }
                        }
                    }
                }
            } else {
                /* 不需要计算,直接使用接口上送内容 */
                mcCouponInfo.setMcActualEndDate(mchntMcInfoBean.getMcActualEndDate());
            }
            /* 活动时间标志 */
            mcCouponInfo.setMcTimeFlag(mchntMcInfoBean.getMcTimeFlag());
            /* 出资方 */
            mcCouponInfo.setSponsor(mchntMcInfoBean.getSponsor());
            /* 参与次数限制 */
            mcCouponInfo.setRestriction(mchntMcInfoBean.getRestriction());
            /* 客户范围 */
            mcCouponInfo.setClientRange(mchntMcInfoBean.getClientRange());
            /* 商户范围 */
            mcCouponInfo.setMerchantRange(mchntMcInfoBean.getMerchantRange());
//            /* 新增商户活动标志 */
//            mcCouponInfo.setNewMchntFlag(mchntMcInfoBean.getNewMchntFlag());
//            /* 限制金额下限 */
//            mcCouponInfo.setAmtLimitFloor(mchntMcInfoBean.getAmtLimitFloor());
//            /* 限制金额上限 */
//            mcCouponInfo.setAmtLimitCelling(mchntMcInfoBean.getAmtLimitCelling());
            /* 预算充值方式 */
            mcCouponInfo.setBudgetRechargeMethod(mchntMcInfoBean.getBudgetRechargeMethod());
            /* 预算 */
            mcCouponInfo.setBudget(mchntMcInfoBean.getBudget());
            /* 银行出资预算 */
            mcCouponInfo.setBankBudget(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 预期参与商户数量 */
            mcCouponInfo.setExpectMchntQty(CommonConstant.ONE_COMMON_CONSTANT);
            /* 银行出资比例 */
            mcCouponInfo.setBankBudgetRatio(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 购买标志 */
            mcCouponInfo.setPurchaseFlag(mchntMcInfoBean.getPurchaseFlag());
            /* 卡券生效时间 */
            mcCouponInfo.setAvailableDate(mchntMcInfoBean.getAvailableDate());
            /* 卡券有效期标志 */
            mcCouponInfo.setCouponDateFlag(mchntMcInfoBean.getCouponDateFlag());
            /* 卡券有效起始日期 */
            mcCouponInfo.setCouponStartDate(mchntMcInfoBean.getCouponStartDate());
            /* 卡券有效结束日期 */
            mcCouponInfo.setCouponEndDate(mchntMcInfoBean.getCouponEndDate());
            /* 卡券相对周期 */
            mcCouponInfo.setCouponPeriod(mchntMcInfoBean.getCouponPeriod());
            /* 卡券库存 */
            mcCouponInfo.setCouponInventory(mchntMcInfoBean.getCouponInventory());
            /* 卡券未领取张数 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponRest())) {
                mcCouponInfo.setCouponRest(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                mcCouponInfo.setCouponRest(mchntMcInfoBean.getCouponRest());
            }
            /* 卡券已领取张数 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponClaimed())) {
                mcCouponInfo.setCouponClaimed(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                mcCouponInfo.setCouponClaimed(mchntMcInfoBean.getCouponClaimed());
            }
            /* 卡券已核销张数 */
            if (StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponClaimed())) {
                mcCouponInfo.setCouponRedeemed(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                mcCouponInfo.setCouponRedeemed(mchntMcInfoBean.getCouponRedeemed());
            }
            /* 审批状态-待提交审批状态 */
            mcCouponInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            //活动发布批量任务状态，卡券类的需要生成卡券，置为0
            mcCouponInfo.setPublishBatchStatus(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 创建人 */
            mcCouponInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcCouponInfo.setCreateTime(globalTimeStamp);
            /* 最后修改人 */
            mcCouponInfo.setLastOprId(mchntMcInfoBean.getLastOprId());
            /* 修改时间 */
            mcCouponInfo.setUpdateTime(globalTimeStamp);
            /* 审批拒绝原因 */
            mcCouponInfo.setAuditRefuseReason(mchntMcInfoBean.getAuditRefuseReason());
            /* 发布拒绝原因 */
            mcCouponInfo.setPublishRefuseReason(mchntMcInfoBean.getPublishRefuseReason());
            /* 备用字段1 */
            mcCouponInfo.setRemark1(mchntMcInfoBean.getRemark1());
            /* 备用字段2 */
            mcCouponInfo.setRemark2(mchntMcInfoBean.getRemark2());
            /* 备用字段3 */
            mcCouponInfo.setRemark2(mchntMcInfoBean.getRemark3());
            /* 备用字段4 */
            mcCouponInfo.setRemark2(mchntMcInfoBean.getRemark4());
            /* 备用字段5 */
            mcCouponInfo.setRemark2(mchntMcInfoBean.getRemark5());
            /* 创建机构 */
            if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                mcCouponInfo.setCrtOrgId(globalQueryOrgId);
            }
            /* 卡券领取渠道 */
            if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getClaimChannelId())) {
                mcCouponInfo.setClaimChannelId(mchntMcInfoBean.getClaimChannelId());
            } else {
                mcCouponInfo.setClaimChannelId(CommonConstant.CLAIM_CHANNEL_DEFAULT);
            }

        } catch (Exception e) {
            rglog.error("转换营销活动信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcCouponInfo;
    }

    /**
     * 插入卡券类营销活动基本信息
     *
     * @param dbsUtil      数据库操作工具类
     * @param mcCouponInfo 卡券类营销活动信息表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 16:35
     */
    private void insertCpMcInfo(DbsUtil dbsUtil, TMMcCouponInfo mcCouponInfo) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.insertSingleCouponMcInfo(mcCouponInfo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将卡券类营销活动基本信息插入临时表中
     *
     * @param dbsUtil      数据库操作工具类
     * @param tmPlatBizTmp 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 15:39
     */
    private void insertTmpCpMcInfo(DbsUtil dbsUtil, TMPlatBizTmp tmPlatBizTmp) throws Exception {

        /* 数据入库 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMcInfoByBank(tmPlatBizTmp);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 卡券类营销活动信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param mcCouponInfo 卡券类营销活动信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 11:49
     */
    private TMPlatBizTmp convertCpMcInfoToTmp(TMMcCouponInfo mcCouponInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(mcCouponInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(mcCouponInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_CP_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packCpMcInfoTmpBizData1(mcCouponInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动卡券类规则信息
     *
     * @param dbsUtil              数据库操作工具类
     * @param mcCouponRuleInfoList 卡券类营销活动规则表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 18:15
     */
    private void insertMcCouponRuleInfo(DbsUtil dbsUtil, List<TMMcCouponRuleInfo> mcCouponRuleInfoList) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.insertCouponRuleInfoListByBank(mcCouponRuleInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动卡券类规则信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcCouponRuleInfo 卡券类营销活动规则表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/12 22:49
     */
    private TMPlatBizTmp convertCpMcRuleInfoToTmp(TMMcCouponRuleInfo tmMcCouponRuleInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcCouponRuleInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcCouponRuleInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_CP_RULE_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_CP_RULE_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packCpMcRuleInfoTmpBizData1(tmMcCouponRuleInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 删除卡券类营销活动基本信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 16:35
     */

    private void deleteCpMcInfo(DbsUtil dbsUtil) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.deleteCpMcInfo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息数据库实体类和接口实体类数据转换
     *
     * @param mchntMcRuleInfoBean 营销活动规则信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcCouponRuleInfo 卡券类营销活动规则表
     * @author liujinan
     * @date 2020/6/12 21:07
     */
    private TMMcCouponRuleInfo convertCouponMcRuleInfo(MchntMcRuleInfoBean mchntMcRuleInfoBean) {

        // 检查上传字段 不能为负数
        checkRuleInfoFieldHasNegativeNumber(mchntMcRuleInfoBean);

        TMMcCouponRuleInfo tmMcCouponRuleInfo = new TMMcCouponRuleInfo();

        try {
            /* 法人机构号 */
            tmMcCouponRuleInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            tmMcCouponRuleInfo.setMcNo(globalMcNo);
            /* 顺序号  */
            tmMcCouponRuleInfo.setRuleIndex(mchntMcRuleInfoBean.getRuleIndex());
            /* 活动门槛 */
            tmMcCouponRuleInfo.setCriteria(mchntMcRuleInfoBean.getCriteria());
            /* 卡券面额 */
            tmMcCouponRuleInfo.setDenomination(mchntMcRuleInfoBean.getDenomination());
            /* 卡券数量 */
            tmMcCouponRuleInfo.setQuantity(mchntMcRuleInfoBean.getQuantity());
            /* 单日核销数量 */
            tmMcCouponRuleInfo.setDayRedeemLimit(mchntMcRuleInfoBean.getDayRedeemLimit());
            /* 购买标志 */
            tmMcCouponRuleInfo.setPurchaseFlag(mchntMcRuleInfoBean.getPurchaseFlag());
            /* 购买金额 */
//            tmMcCouponRuleInfo.setPurchaseAmt(mchntMcRuleInfoBean.getPurchaseAmt());
            /* 批量任务状态 */
            tmMcCouponRuleInfo.setBatchTaskStatus(CommonConstant.PUBLISH_BATCH_INITIAL);
            /* 创建人 */
            tmMcCouponRuleInfo.setOprId(globalOprId);
            /* 创建时间 */
            tmMcCouponRuleInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动规则信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return tmMcCouponRuleInfo;
    }

    /**
     * 删除营销活动卡券类规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/12 18:15
     */
    private void deleteCouponRuleInfoList(DbsUtil dbsUtil) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.deleteCouponRuleInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动卡券类规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 全局变量赋值
     *
     * @param mchntMcManageRequest 接口请求对象
     * @throws BizException 异常信息
     * @author liujinan
     * @date 2020/7/21 16:37
     */
    private void messageValidation(MchntMcManageRequest mchntMcManageRequest) throws Exception {

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getHeader().getTransDate())) {
            rglog.error("交易日期必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalTxnDate = mchntMcManageRequest.getHeader().getTransDate();
        }

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getHeader().getTransTime())) {
            rglog.error("交易时间必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getHeader().getInstId())) {
            rglog.error("法人机构号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalInstId = mchntMcManageRequest.getHeader().getInstId();
        }

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getHeader().getTraceNo())) {
            rglog.error("流水号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalTraceNo = mchntMcManageRequest.getHeader().getTraceNo();
        }

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getQueryId())) {
            rglog.error("查询主体必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalOprId = mchntMcManageRequest.getQueryId();
        }

        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getQueryOrgId())) {
            rglog.error("查询主体所属机构必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryOrgId = mchntMcManageRequest.getQueryOrgId();
        }

        //营销活动类型
        if (StringUtil.isNullorEmpty(mchntMcManageRequest.getMcInfoObj().getMcType())) {
            rglog.error("营销活动类型必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            String mcType = mchntMcManageRequest.getMcInfoObj().getMcType();
            if (mcType.startsWith(CommonConstant.ZERO_COMMON_CONSTANT)) {
                globalMcType = CommonConstant.ZERO_COMMON_CONSTANT;
            } else {
                globalMcType = CommonConstant.ONE_COMMON_CONSTANT;
            }
        }

        String queryType = mchntMcManageRequest.getQueryType();
        String queryRole = mchntMcManageRequest.getQueryRole();
        String oprType = mchntMcManageRequest.getOprType();

        if (StringUtil.isNullorEmpty(queryType) || StringUtil.isNullorEmpty(queryRole) || StringUtil.isNullorEmpty(oprType)) {
            rglog.error("查询类型,查询主体角色,操作类型 不能为空");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());

        //查询商户所属机构及上属机
        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        List<TMMcOrgInfo> tmMcOrgInfoList = mcOrgInfoMapper.selectAllFrontMcOrgInfoListByInstIdOrgId(globalInstId, globalQueryOrgId);
        if (null == tmMcOrgInfoList || tmMcOrgInfoList.size() == 0) {
            rglog.error("查询当前角色<{}> 商户所属机构<{}>及其上属机构失败!", mchntMcManageRequest.getQueryRole(), globalQueryOrgId);
            throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
        }
        globalOrgInfoList = tmMcOrgInfoList.stream().map(this::convertMoneyOffMcRuleInfo).collect(Collectors.toList());

        //营销编码
        globalMcNo = mchntMcManageRequest.getMcInfoObj().getMcNo();
        if (globalMcNo != null) {
            McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
            //接口上送的营销活动编号不为空，则首先判断数据库存储的原营销活动商户信息时否和当前操作的商户是同一个，不是同一个不允许操作
            //减免类
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(globalMcType)) {
                //减免类营销活动信息正式表查询
                TMMcMoneyOffInfo tmMcMoneyOffInfo = null;
                tmMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
                if (null == tmMcMoneyOffInfo) {
                    //获取营销活动信息失败
                    rglog.error("获取减免类营销活动信息失败,  MC_NO=<{}>", globalMcNo);
                    throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
                }
                if (null != tmMcMoneyOffInfo.getOprId()) {
                    if (!globalOprId.equals(tmMcMoneyOffInfo.getOprId())) {
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", queryRole, globalOprId);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                }
            }
            //卡卷类
            else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
                //卡券类营销活动信息正式表查询
                TMMcCouponInfo tmMcCouponInfo = null;
                tmMcCouponInfo = (TMMcCouponInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
                if (null == tmMcCouponInfo) {
                    //获取营销活动信息失败
                    rglog.error("获取卡卷类营销活动信息失败,  MC_NO=<{}>", globalMcNo);
                    throw new BizException(RespCodeEnum.GET_COUPON_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_COUPON_MC_DETAIL_ERROR.getRespDesc());
                }
                if (null != tmMcCouponInfo.getOprId()) {
                    if (!globalOprId.equals(tmMcCouponInfo.getOprId())) {
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", queryRole, globalOprId);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                }
            }
        }

    }

    /**
     * 商户营销活动机构信息转换
     *
     * @param tMMcOrgInfo 营销活动机构信息表对象
     * @author liujinan
     * @date 22020/9/10 21:07
     */
    private McOrgInfoBean convertMoneyOffMcRuleInfo(TMMcOrgInfo tMMcOrgInfo) {

        McOrgInfoBean mcOrgInfoBean = new McOrgInfoBean();
        try {
            /* 机构编号 */
            mcOrgInfoBean.setOrgId(tMMcOrgInfo.getOrgId());
            /* 机构层级 */
            mcOrgInfoBean.setOrgHierarchy(tMMcOrgInfo.getOrgHierarchy());
            /* 机构名称  */
            mcOrgInfoBean.setOrgName(tMMcOrgInfo.getOrgName());
            /* 操作类型 */
            mcOrgInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);

        } catch (Exception e) {
            rglog.error("转换营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcOrgInfoBean;
    }

    /**
     * 检查 上送 活动信息 金额字段不能为负数
     *
     * @param mchntMcInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkMcInfoObjFieldHasNegativeNumber(MchntMcInfoBean mchntMcInfoBean) {
        /* 参与次数限制 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getRestriction()) && new BigDecimal(mchntMcInfoBean.getRestriction()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 预算 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getBudget()) && new BigDecimal(mchntMcInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 卡券库存 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponInventory()) && new BigDecimal(mchntMcInfoBean.getCouponInventory()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 卡券未领取张数 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponRest()) && new BigDecimal(mchntMcInfoBean.getCouponRest()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

        /* 卡券已领取张数 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponClaimed()) && new BigDecimal(mchntMcInfoBean.getCouponClaimed()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 卡券已核销张数 */
        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getCouponClaimed()) && new BigDecimal(mchntMcInfoBean.getCouponClaimed()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
//        /* 限制金额下限	amtLimitFloor*/
//        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getAmtLimitFloor()) && new BigDecimal(mchntMcInfoBean.getAmtLimitFloor()).compareTo(zero) < 0){
//            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
//        }
//        /*限制金额上限	amtLimitCelling*/
//        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getAmtLimitCelling()) && new BigDecimal(mchntMcInfoBean.getAmtLimitCelling()).compareTo(zero) < 0){
//            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
//        }
//        /*银行出资预算	bankBudget*/
//        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getBankBudget()) && new BigDecimal(mchntMcInfoBean.getBankBudget()).compareTo(zero) < 0){
//            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
//        }
//        /* 预期参与商户数量	expectMchntQty*/
//        if (!StringUtil.isNullorEmpty(mchntMcInfoBean.getExpectMchntQty()) && new BigDecimal(mchntMcInfoBean.getExpectMchntQty()).compareTo(zero) < 0){
//            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
//        }

    }

    /**
     * 检查 上送 活动信息 金额字段不能为负数
     *
     * @param mchntMcRuleInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkRuleInfoFieldHasNegativeNumber(MchntMcRuleInfoBean mchntMcRuleInfoBean) {
        /* 活动门槛 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getCriteria()) && new BigDecimal(mchntMcRuleInfoBean.getCriteria()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠力度下限 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDiscountFloor()) && new BigDecimal(mchntMcRuleInfoBean.getDiscountFloor()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

        /* 优惠力度上限 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDiscountCelling()) && new BigDecimal(mchntMcRuleInfoBean.getDiscountCelling()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 总优惠数量 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDiscountQuantity()) && new BigDecimal(mchntMcRuleInfoBean.getDiscountQuantity()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单次优惠限制 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDiscountLimit()) && new BigDecimal(mchntMcRuleInfoBean.getDiscountLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠总预算 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getBudget()) && new BigDecimal(mchntMcRuleInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单日消耗预算 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getBudgetDayLimit()) && new BigDecimal(mchntMcRuleInfoBean.getBudgetDayLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 卡券面额 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDenomination()) && new BigDecimal(mchntMcRuleInfoBean.getDenomination()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 卡券数量 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getQuantity()) && new BigDecimal(mchntMcRuleInfoBean.getQuantity()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单日核销数量 */
        if (!StringUtil.isNullorEmpty(mchntMcRuleInfoBean.getDayRedeemLimit()) && new BigDecimal(mchntMcRuleInfoBean.getDayRedeemLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

    }

    /**
     * 注册定时任务
     *
     * @param taskName   任务名称
     * @param settleDate 清算日期 不上送 默认当前日期
     * @param regTime    执行日期 不上送 立即执行
     * @param taskBatch  批次号后五位清算日期内唯一
     * @param taskParam  营销活动编号
     * @throws Exception
     */
    private void timingTask(String taskName, String settleDate, String regTime, String taskBatch, String taskParam, DbsUtil dbsUtil) throws Exception {
        rglog.info("任务名称<{}> 清算日期<{}> 执行时间<{}> 批次号<{}> 营销活动编号<{}>", taskName, settleDate, regTime, taskBatch, taskParam);
        SysParamService sysParamService = new SysParamServiceImpl();
        SysParam sysParam = sysParamService.getSysParamInfo(AppParamConstant.DEFAULT_INSTID, MOMP_RBDP_ADDRESS, MOMP_RBDP_REGISTER_ADDRESS);
        if (null == sysParam) {
            rglog.error("获取批量任务注册地址失败！");
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.FAILED_TO_GET_RBDP_REGISTER_ADDRESS.getRespCode(), RespCodeEnum.FAILED_TO_GET_RBDP_REGISTER_ADDRESS.getRespDesc());
        }
        //批量注册地址
        String rbdpserver = sysParam.getParamValue();
        RealTimeRegisterClient a = RbdpClient.getIntance1(rglog, rbdpserver);

        int ret = a.registerTask(taskName, settleDate, settleDate.concat(DateUtil.getCurrentTime()), taskBatch.concat(MompToolUtil.getAppoint(MompDateUtil.getTime(), 0, 5)), taskParam);
        rglog.info("卡券生成实时任务注册返回：ret {}", ret);
        String result = "";
        if (0 != ret) {
            result = "注册失败: " + RbdpClient.getIntance1(rglog, rbdpserver).getError();
            rglog.error("实时任务注册返回：ret {}", result);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.FAILED_TO_TIME_TASK.getRespCode(), RespCodeEnum.FAILED_TO_TIME_TASK.getRespDesc());
        } else {
            result = "注册成功.";
            rglog.info("实时任务注册返回：ret {}", result);
        }
    }

}
